import Vue from 'vue'
import Router from 'vue-router'
import routes from './modules/routes'
import platform from './modules/platform'

Vue.use(Router)

const createRouter = () => new VueRouter({
  routes,
  scrollBehavior() {
    return { x: 0, y: 0 }
  }
})

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}


export const constantRoutes = [
  ...routes
]

export const asyncRoutes = [
  ...platform
]

const originalPush = router.push
router.push = function push(location, onResolve, onReject) {
  // if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}

export default router